package org.idontknow.helloworld;

import org.idontknow.logger.TraceFactory;
import org.idontknow.logger.Trace;

import java.io.File;
import java.util.Properties;
import java.util.HashMap;
import java.util.ArrayList;
//import java.lang.CloneNotSupportedException;

public class Hello implements Runnable{

  public static Trace log;
  public static Properties props;

  public Hello() {
    props = System.getProperties();
    log = TraceFactory.getTrace();
    //      log.clone();
  }

  //the main method, here we can control the one we say hello to:)

  public static void main(String[] args) {
    Hello hello = new Hello();

    hello.testSysProperties();
    hello.testLog();
    hello.testSomeStringStuff();
    hello.testThread();
    hello.hashMapTry();

    ArrayList<Integer> testArrayInitSize = new ArrayList<Integer>();
    System.out.println("size of a newly created ArrayList is : " + testArrayInitSize.size() + "\n");

    //strange definition of array...
    String monTableau [] = new String[1];
    monTableau[0] = "this is a test string";
    System.out.println(monTableau[0]);
  }

  //various hellos...annoying ah?

  public void run() {
    System.out.println("coucou~~~im in a thread!");
  }

  public void testSysProperties() {
    props.list(System.out);
    System.out.println(props.getProperty("pwd"));

    System.out.println(Integer.MAX_VALUE);
    System.out.println(File.separator);
    System.out.println(File.pathSeparator);
  }

  public void testLog() {
    log.debug("coucou~~~");
    try{
      Thread.sleep(300);
    }catch(Exception e) {
      e.printStackTrace();
    }
    log.error("error of wut?");
    System.out.println("just to try out how long this will take...");
    log.info("blablabla...iv really a lot of blas to say...");
  }

  public void testSomeStringStuff() {
    System.out.println("Hello World!");
    System.out.println("Hello World!".substring(1));

    String str1 = "abcde";
    System.out.println(str1.substring(1,4));

    String str2 = new String("abcde");
    System.out.println(str1 == str2);

    StringBuffer buffer = new StringBuffer("today");
    String str = new String(buffer);
    buffer.append("-");
    str.replace("a","o");
    System.out.println(buffer + str.replace("a", "o"));

    String testLookup = "abcabcabcabc";
    System.out.println(testLookup.indexOf("abc"));

    System.out.println((int)'b');
    System.out.println((char)98);
  }

  public void hashMapTry() {
    HashMap<String, String> map = new HashMap<String, String>(128, 0.75f);
    map.put("test key", "test value");
    log.info(map.get("test key"));
    log.info(map.get("no-exist key"));
  }

  public void testThread() {    
    Hello inThread = new Hello();
    new Thread(inThread).start();
  }
}
